from django.http import HttpResponse
from django.shortcuts import render
from .forms import MessageForm,Register
# Create your views here.
def index(request):
    # return HttpResponse("Hello, world. You're at the polls index.")
    if request.method == "GET":
        mform = MessageForm()
        return render(request,"people_index.html",{"form":mform})

    elif request.method == "POST":
        mform = MessageForm(request.POST)
        if mform.is_valid():
            title = mform.cleaned_data['title']
            content = mform.cleaned_data['content']
            email = mform.cleaned_data['email']
            return HttpResponse(f"{content},{email},{title}")
        else:
            return HttpResponse("表单验证失败")

def register(request):
    if request.method == "GET":
        return render(request,"people_register.html")
    elif request.method == "POST":
        form = Register(request.POST)
        if form.is_valid():
            ph = form.cleaned_data.get("ph")
            return HttpResponse(f"{ph}")
        else:
            return HttpResponse("手机验证失败")










